package com.collectplus.express.city;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.collectplus.express.R;
import com.collectplus.express.model.CalculateProvinceBean;
import com.collectplus.express.model.ProvinceBean;

public class AreaAdapter extends BaseAdapter {

	ArrayList<ProvinceBean.Province> mArr;
	private LayoutInflater mInflater;

	public AreaAdapter(Context context, ArrayList<ProvinceBean.Province> arr) {
		mArr = arr;
		mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		return mArr.size();
	}

	@Override
	public Object getItem(int position) {
		return mArr.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	public void notifyDataSetChanged(ArrayList<ProvinceBean.Province> arr) {
		mArr = arr;
		super.notifyDataSetChanged();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.city_item, parent, false);
			holder = new ViewHolder();
			holder.tvName = (TextView) convertView.findViewById(R.id.city_item_name);
			convertView.setTag(holder);
		}else{
			holder = (ViewHolder) convertView.getTag();			
		}
		holder.tvName.setText(mArr.get(position).getName());
		return convertView;
	}

	private class ViewHolder {
		TextView tvName;
	}
}
